package com.useoften;

//测试字符串相关类
public class TestString {
    public static void main(String[] args) {
        String str = "abc";

        /*StringBuilder*/
        StringBuilder sb = new StringBuilder();
        for (int i=0;i<7;i++){
            sb.append((char)('a'+i));//追加单个字符
        }
        System.out.println(sb.toString());//转换成String输出
        sb.append(",I can sing my abc!");//追加字符串
        System.out.println(sb.toString());

        /*StringBuffer*/
        StringBuffer sb2 = new StringBuffer("可爱的小狗");
        //写方法链是因为返回的是this，而不是新的字符串，可以不停对字符串修改
        sb2.insert(0,"爱").insert(0,"我");
        System.out.println(sb2);
        sb2.delete(0,2);
        System.out.println(sb2);

        sb2.deleteCharAt(0).deleteCharAt(0).deleteCharAt(0);//删除某个字符
        System.out.println(sb2);
        System.out.println(sb2.charAt(0));//获取某个字符
        System.out.println(sb2.reverse());//字符串逆序
    }
}
